using System;

using FineCollection.Intf;




namespace FineCollection.Arrays
{
    public class ArrQueue<T> : ArrBaseCollection<T>, WQueue<T>
    {

        /// <summary>
        /// Constructs an empty array-based list.
        /// </summary>
        public ArrQueue() 
            : base(1)
        {}


        /// <summary>
        /// Enqueues the item (adds the item to the tail of the queue).
        /// </summary>
        /// <param name="item">item to enqueue.</param>
        public void Enqueue(T item)
        {
            InternalAddItem(item);
        }


        /// <summary>
        /// Dequeues an item (excludes the item from the head of the queue 
        /// and returns the excluded item).
        /// </summary>
        /// <returns>dequeued item.</returns>
        /// <exception cref="CollectionIsEmpty">if the queue is empty.</exception>
        public T Dequeue()
        {
            T top = First;
            RemoveFirstElement();
            return top;
        }


        /// <summary>
        /// Represents a quick indexed access to the specified item.
        /// </summary>
        /// <remarks>
        /// The given index must be in [ 1 .. Count ] inclusive.
        /// </remarks>
        /// <param name="index">index of item to access.</param>
        /// <exception cref="CollectionIsEmpty">when the collection is empty.</exception>
        /// <exception cref="IndexOutOfBoundsException">when index is incorrect.</exception>
        /// <seealso cref="RRandomList{T}.FirstIndex"/>
        /// <seealso cref="RRandomList{T}.LastIndex"/>
        public new T this[int index]
        {
            get 
            {           
                int intIndex = CalcInternalIndex(index);
                return ar[intIndex];
            }
        }
    }
}